<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>编辑用户</title>
  </head>
<script type="text/javascript">
	(function($){  
     $.imap = function(){  
          var imap = this.map = {};  
          this.get = function(key){  
              var val = eval("imap."+key);  
              return  (typeof val === undefined) ? null : val;  
          };  
          this.set = function(key,value){  
              eval("imap."+key+"=value");  
          };  
     };  
  })(jQuery); 
  
  var map = new jQuery.imap();
  var priceMap = new jQuery.imap();
   function changeType(value){
   		$("#money").show();
   		$("#moneyLabel").show();
   		$("#productLabel").show();
    	$("#productId").show();
   		$("#moneyLabel").text("消费金额:");
   		$("#scoreLabel").text("返回积分：");
   		$("#lookupCostLog").hide();
   		$("#moneyP").show();
   		$("#productP").show();
   		$("#scoreP").show();
   		//$("#lookupCostLogLabel").hide();
   		if(value == 'CASH'){
    		//$("#productLabel").hide();
    		//$("#productId").hide();
    	}else if(value == 'SCORE'){
    		$("#money").removeClass("required");
    		$("#money").hide();
    		$("#moneyP").hide();
    		$("#productLabel").hide();
    		$("#productP").hide();
    		$("#scoreLabel").text("扣除积分：");
    	}else if(value == 'SAVING'){
    		$("#productLabel").hide();
    		$("#productId").hide();
    		$("#productP").hide();
    		//$("#scoreLabel").hide();
    		//$("#score").hide();
    		//$("#score").removeClass("required");
    	}else if(value == "FEEDBACK"){
    		$("#lookupCostLog").show();
    		//$("#lookupCostLogLabel").show();
    		$("#moneyLabel").text("返回金额:");
   			$("#scoreLabel").text("扣除积分：");
    	}
   }
   
   function changeProduct(value){
   		//$("#score").val(map.get(value)) ;
   		//$("#money").val(priceMap.get(value)) ;
   		$("#score").val($("#productPoint").val()) ;
   		$("#money").val($("#productPrice").val()) ;
   		
   }
    	
	</script>
  <body>
	<div class="pageContent">
		<form method="post" action="<%=path %>/cost/saveCost.action" class="pageForm required-validate" onsubmit="return validateCallback(this, navTabAjaxDone);">
			<div class="pageFormContent" layoutH="56">
				<p>
					<label>实例卡：</label>
					<input id="cardEntityId" name="costVO.cardEntity.id" value="<s:property value="costVO.cardEntity.id" />" class="required" type="hidden" size="30" alt="请输入实例卡"/>
					<input name="costVO.cardEntity.memberName" value="<s:property value="costVO.cardEntity.memberName" />" readonly size="30" alt="请输入实例卡"/>
					<input name="costVO.customer.id" value="<s:property value="costVO.cardEntity.customerId" />" type="hidden" readonly size="30" />
				</p>
				<p>
					<label>消费类型：</label>
					<select id="costType" name="costVO.type" onchange="changeType(this.value);" class="combox required">
                        <option value="">==选择类型==</option>
                        <c:forEach var="item" items="${costTypes}">
                        	<c:if test="${item.name != 'TIMES'}">
                        		<option value="${item.name}" ${costVO.type eq item.name ? "selected" : "" }>${item.title}</option>
                        	</c:if>
                        </c:forEach>
                   </select>
                   <a style="display:none" id="lookupCostLog" class="btnLook" href="<%=path %>/cost/listCost.action?searchType=lookup&costVO.cardEntity.id=${costVO.cardEntity.id}" lookupGroup="costVO" alt="选择消费记录">选择消费记录</a>
				</p>
				<p id="moneyP">
					<label id="moneyLabel">消费金额：</label>
					<input id="money"  name="costVO.money" value="<s:property value="costVO.money" />" class="required" type="text" size="30" />
				</p>
				
				<p id="scoreP">
					<label id="scoreLabel">返回积分：</label>
					<input id="score"  name="costVO.score" value="<s:property value="costVO.score" />" class="required" type="text" size="30" />
				</p>
				
				<p id="productP">
					<label id="productLabel">商品：</label>
					<input name="costVO.productId" value="<s:property value="costVO.productId" />" type="hidden" onchange="changeProduct(this.value);">
					<input onclick="$('#costAdd_a_btnLook').trigger('click');" style="cursor: pointer;" name="costVO.productName" value="<s:property value="costVO.productName" />" readonly>
					<a class="btnLook" id="costAdd_a_btnLook" href="<%=path %>/product/listProduct.action?searchType=lookup" lookupGroup="costVO">选择</a>
									
					<!-- 
					<select id="productId" name="costVO.product.id" onchange="changeProduct('P'+this.value);">
                        <option value="">==选择商品==</option>
                        <c:forEach var="item" items="${products}">
                        	<option value="${item.id}" ${costVO.product.id eq item.id ? "selected" : "" }>${item.name}</option>
                        	<script>map.set('P${item.id}','${item.point}');</script>
                        	<script>priceMap.set('P${item.id}','${item.price}');</script>
                        </c:forEach>
                   </select>
                    -->
				</p>
				

				<p>
					<label>说明：</label>
					<textarea  id="costVO.description" name="costVO.description" value="<s:property value="costVO.description" />"  type="text" size="30">${costVO.description}</textarea>
				</p>
				<p id="CostCount" style="margin-left:30px;margin-top:50px;float:center"></p>
			</div>
			
			<div class="formBar">
				<ul>
					<li><div class="buttonActive"><div class="buttonContent"><button type="submit">保存</button></div></div></li>
					<li>
						<div class="button"><div class="buttonContent"><button type="button" class="close">取消</button></div></div>
					</li>
				</ul>
			</div>
		</form>
	</div>
  </body>
</html>